// 碰撞检测工具
export const collision = {
  // 检查两个点是否碰撞
  pointCollision(point1, point2) {
    return point1.x === point2.x && point1.y === point2.y
  },

  // 检查点是否在边界内
  isInBounds(point, bounds) {
    return (
      point.x >= 0 &&
      point.x < bounds.width &&
      point.y >= 0 &&
      point.y < bounds.height
    )
  },

  // 检查蛇是否吃到食物
  checkFoodCollision(snakeHead, food) {
    return this.pointCollision(snakeHead, food)
  },

  // 检查蛇是否撞到自己
  checkSelfCollision(snake) {
    const head = snake.segments[0]
    return snake.segments.slice(1).some(segment => 
      this.pointCollision(head, segment)
    )
  }
}
